import axios from 'axios'
export default {
  namespaced: true,
  state: () => ({
    // token: ''
    // 将token的初始值从本地获取
    // token: localStorage.getItem('token') -->插件替代
    userInfo: {}
  }),
  mutations: {
    updateToken (state, token) {
      state.token = token
      // 每次修改token后将其存入本地
    //   localStorage.setItem('token', token)  -->插件替代
    },
    updateUserInfo (state, info) {
      state.userInfo = info
    }
  },
  actions: {
    async getUserInfo (ctx) {
      // const res = await axios.get('/my/userinfo', { headers: { Authorization: ctx.state.token } })
      const res = await axios.get('/my/userinfo')
      // console.log(res)
      if (res.data.code === 0) {
        ctx.commit('updateUserInfo', res.data.data)
        // console.log(res.data.data)
      }
    }
  }
}
